package pers.qianyu.month_202101.date_20210106;

import org.junit.*;

import java.util.*;

/**
 * 830. 较大分组的位置
 * https://leetcode-cn.com/problems/positions-of-large-groups/
 *
 * @author mizzle rain
 * @date 2021-01-06 15:43
 */
public class LargeGroupPositions {
    public List<List<Integer>> largeGroupPositions(String s) {
        List<List<Integer>> res = new ArrayList<>();
        int len = s.length();
        int slow = 0, fast = 1;
        for (; fast < len; fast++) {
            char ch = s.charAt(fast);
            if (ch != s.charAt(slow)) {
                if (fast - slow >= 3) {
                    res.add(Arrays.asList(slow, fast - 1));
                }
                slow = fast;
            }
        }
        if (fast - slow >= 3) res.add(Arrays.asList(slow, fast - 1));
        return res;
    }

    @Test
    public void test1() {
        List<List<Integer>> result = new LargeGroupPositions()
                .largeGroupPositions("abbxxxxzyy");
        result.forEach(System.out::println);
    }

    @Test
    public void test2() {
        List<List<Integer>> result = new LargeGroupPositions()
                .largeGroupPositions("abc");
        result.forEach(System.out::println);
    }

    @Test
    public void test3() {
        List<List<Integer>> result = new LargeGroupPositions()
                .largeGroupPositions("abcdddeeeeaabbbcd");
        result.forEach(System.out::println);
    }

    @Test
    public void test4() {
        List<List<Integer>> result = new LargeGroupPositions()
                .largeGroupPositions("aba");
        result.forEach(System.out::println);
    }
}
